package com.knowledge.business.controller;


import java.util.Arrays;
import java.util.List;
import java.io.IOException;

import com.knowledge.common.annotation.Log;
import com.knowledge.common.core.controller.BaseController;
import com.knowledge.common.core.domain.AjaxResult;
import com.knowledge.common.enums.BusinessType;
import com.knowledge.common.utils.poi.ExcelUtil;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.knowledge.business.domain.TMemberLevel;
import com.knowledge.business.service.ITMemberLevelService;
import com.knowledge.common.core.page.TableDataInfo;

/**
 * 用户等级Controller
 *
 * @author zhaoyk
 * @date 2025-09-17
 */
@RestController
@RequestMapping("/business/level")
public class TMemberLevelController extends BaseController {
    @Autowired
    private ITMemberLevelService tMemberLevelService;

    /**
     * 查询用户等级列表
     */
//@RequiresPermissions("business:level:list")
    @GetMapping("/list")
    public TableDataInfo list(TMemberLevel tMemberLevel) {
        startPage();
        List<TMemberLevel> list = tMemberLevelService.selectTMemberLevelList(tMemberLevel);
        return getDataTable(list);
    }

    /**
     * 导出用户等级列表
     */
    //@RequiresPermissions("business:level:export")
    @Log(title = "用户等级", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TMemberLevel tMemberLevel) {
        List<TMemberLevel> list = tMemberLevelService.selectTMemberLevelList(tMemberLevel);
        ExcelUtil<TMemberLevel> util = new ExcelUtil<TMemberLevel>(TMemberLevel.class);
        util.exportExcel(response, list, "用户等级数据");
    }

    /**
     * 获取用户等级详细信息
     */
    //@RequiresPermissions("business:level:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id) {
        return AjaxResult.success(tMemberLevelService.getById(id));
    }

    /**
     * 新增用户等级
     */
    //@RequiresPermissions("business:level:add")
    @Log(title = "用户等级", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TMemberLevel tMemberLevel) {
        return toAjax(tMemberLevelService.save(tMemberLevel));
    }

    /**
     * 修改用户等级
     */
    //@RequiresPermissions("business:level:edit")
    @Log(title = "用户等级", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TMemberLevel tMemberLevel) {
        return toAjax(tMemberLevelService.updateById(tMemberLevel));
    }

    /**
     * 删除用户等级
     */
    //@RequiresPermissions("business:level:remove")
    @Log(title = "用户等级", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids) {
        return toAjax(tMemberLevelService.removeByIds(Arrays.asList(ids)));
    }
}
